package com.example.pinkcat.client;

import android.content.Context;
import android.content.SharedPreferences;


import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class AddCookiesInterceptor implements Interceptor {
    private Context context;

//    public AddCookiesInterceptor(Context context) {
//        super();
//        this.context = context;
//
//    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        final Request.Builder builder = chain.request().newBuilder();
        if(userStaticMsg.JSESSIONID!=null){
            builder.addHeader("style",  userStaticMsg.style);
            builder.addHeader("Cookie",  userStaticMsg.JSESSIONID);
        }




//        SharedPreferences sharedPreferences = context.getSharedPreferences("cookie", Context.MODE_PRIVATE);

//最近在学习RxJava,这里用了RxJava的相关API大家可以忽略,用自己逻辑实现即可
//        Observable.just(sharedPreferences.getString("cookie", ""))
//                .subscribe(new Action1<String>() {
//                    @Override
//                    public void call(String cookie) {
//                        //添加cookie
//                        builder.addHeader("Cookie", cookie);
//                    }
//                });
        return chain.proceed(builder.build());
    }
}
